<template>
  <div class="gray-border">
    <transition name="el-fade-in-linear">
      <div v-if="searchShow" class="search">
        <div class="search-head">
          <div class="container">
            <div :class="['search-form', searchAini ? 'form-enlarge' : 'form-narrow']">
              <div class="form-left">
                <input type="text" placeholder="关键字">
                <button>
                  <i class="el-icon-search"></i>
                </button>
              </div>
              <div class="close" @click="narrow">
                <i class="el-icon-close"></i>
              </div>
            </div>
          </div>
        </div>
      </div>
    </transition>
      <LoginCommod class="login"/>
      <el-collapse-transition>
        <barCommod v-if="barShow" class="bar"/>
      </el-collapse-transition>
      <div class="header">
        <div class="container cl">
          <div class="logo to-one-right">
            <img src="../assets/images/logo-black.png" alt="">
          </div>
          <!--<div class="menu to-left" :style="{transform: proShow ? 'none' : ''}">-->
          <div class="menu to-one-left">
            <ul>
              <li
                :class="{'active': $route.path == '/'}"
                @click="$router.push('/')">
                首页
                <p class="hr"></p>
              </li>
              <li
                :class="{'active': $route.path == '/aboutus'}"
                @click="$router.push('/aboutus')">
                关于我们
                <p class="hr"></p>
              </li>
              <li
                @mouseover="proShow = true"
                @mouseleave="proShow = false"
                :class="{'active': getRouter() || proShow}"
                @click="$router.push('/product')">
                产品
                <p class="hr"></p>
              </li>
              <li
                @click="$router.push('/freightInquiry')"
                :class="{'active': $route.path == '/freightInquiry'}">
                查价
                <p class="hr"></p>
              </li>
              <li
                @click="searchShow = true">
                <i class="el-icon-search"></i>
                <p class="hr"></p>
              </li>
            </ul>
            <img
              @click="barShow = !barShow"
              class="show-bar"
              src="../assets/images/menu-green.png"
              alt="">
          </div>

          <el-collapse-transition>
            <div v-show="proShow"
                 @mouseover="proShow = true"
                 @mouseleave="proShow = false" class="products">
              <ul>
                <li @click.stop="$router.push('/fcl')">FCL下单</li>
                <li @click.stop="$router.push('/lcl')">LCL下单</li>
                <li @click.stop="$router.push('/airTransport')">空运</li>
                <li @click.stop="$router.push('/express')">快递下单</li>
              </ul>
            </div>
          </el-collapse-transition>
        </div>
      </div>
  </div>
</template>

<script>
  import barCommod from './Bar'
  import LoginCommod from './Login'
  import ScrollReaveal from 'scrollreveal'
  export default {
    name: 'Head',
    data () {
      return {
        barShow: false,
        searchShow: false,
        searchAini: true,
        proShow: false,
        scrollReveal: ScrollReaveal()
      }
    },
    created () {
    },
    methods: {
      getRouter () {
        if (this.$route.path == '/product' || this.$route.path == '/fcl' || this.$route.path == '/lcl' || this.$route.path == '/airTransport' || this.$route.path == '/express') {
          return true
        } else {
          return false
        }
      },
      narrow () {
        this.searchAini = false
        setTimeout(() => {
          this.searchShow = false
          this.searchAini = true
        }, 500)
      }
    },
    mounted () {
      this.scrollReveal.reveal('.to-one-right', {
        distance: '50px',
        origin: 'left',
        duration: 1000,
        easing: 'linear',
        reset: false,
        beforeReveal: function (ele) {
          ele.style.transform = 'none'
        }
      })

      this.scrollReveal.reveal('.to-one-left', {
        distance: '50px',
        origin: 'right',
        duration: 1000,
        easing: 'linear',
        reset: false,
        beforeReveal: function (ele) {
          ele.style.transform = 'none'
        }
      })

      this.scrollReveal.reveal('.to-right', {
        distance: '50px',
        origin: 'left',
        duration: 1000,
        easing: 'linear',
        reset: true,
        beforeReveal: function (ele) {
          ele.style.transform = 'none'
        }
      })

      this.scrollReveal.reveal('.to-left', {
        distance: '50px',
        origin: 'right',
        duration: 1000,
        easing: 'linear',
        reset: true,
        beforeReveal: function (ele) {
          ele.style.transform = 'none'
        }
      })

      this.scrollReveal.reveal('.to-top', {
        distance: '100px',
        origin: 'bottom',
        duration: 1000,
        easing: 'linear',
        reset: true,
        beforeReveal: function (ele) {
          ele.style.transform = 'none'
        }
      })

      this.scrollReveal.reveal('.to-bottom', {
        distance: '50px',
        origin: 'top',
        duration: 1000,
        easing: 'linear',
        reset: true,
        beforeReveal: function (ele) {
          ele.style.transform = 'none'
        }
      })
    },
    components: {
      barCommod,
      LoginCommod
    }
  }
</script>

<style scoped>

  .header {
    background: #fff;
  }

  .logo {
    float: left;
    width: 130px;
    margin: 20px 0;
  }

  .bar {
    top: 80px;
  }

  .logo img {
    max-width: 100%;
  }

  .menu {
    float: right;
    line-height: 75px;
    margin-top: 19px;
  }

  .menu ul {
    float: left;
  }

  .menu li {
    float: left;
    list-style: none;
    padding: 0 40px;
    cursor: pointer;
    font-size: 18px;
  }

  .hr {
    position: relative;
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
  }


  .menu li.active {
    color: #0b6835;
  }

  .menu li .hr:after {
    content: '';
    display: inline-block;
    height: 3px;
    background: #0b6835;
    left: 0;
    bottom: 0px;
    width: 0;
  }

  .menu li.active .hr:after {
    width: 100%;
  }

  .menu li:hover {
    animation: changeColor 1s;
    -webkit-animation: changeColor 1s; /* Safari 与 Chrome */
    -webkit-animation-fill-mode: forwards;
    animation-fill-mode: forwards;
  }

  .menu li:hover .hr:after {
    animation: changeWidth 0.5s;
    -webkit-animation: changeWidth 0.5s; /* Safari 与 Chrome */
    -webkit-animation-fill-mode: forwards;
    animation-fill-mode: forwards;
  }

  @keyframes changeWidth
  {
    from {
      width: 0;
    }
    to {
      width: 100%;
    }
  }

  @-webkit-keyframes changeWidth
  {
    from {
      width: 0;
    }
    to {
      width: 100%;
    }
  }

  @keyframes changeColor
  {
    from {
      color: #444;
    }
    to {
      color: #0b6835;
    }
  }

  @-webkit-keyframes changeColor
  {
    from {
      color: #444;
    }
    to {
      color: #0b6835;
    }
  }

  .show-bar {
    float: right;
    margin-top: 10px;
    margin-left: 45px;
    cursor: pointer;
  }

  .login {
    position: absolute;
    right: 20px;
    top: 20px;
    cursor: pointer;
  }

  .products {
    position: absolute;
    width: 100%;
    left: 0;
    top: 96px;
    height: 60px;
    background: rgba(42, 126, 62, 0.7);
    z-index: 9999;
    text-align: center;
  }

  .products ul {
    width: 1000px;
    margin: 0 auto;
    float: none;
    margin-top: 20px;
    margin-bottom: 10px;
  }

  .products li {
    display: inline-block;
    padding: 0 70px;
    margin: 0;
    line-height: 20px;
    font-size: 15px;
    color: #fff !important;
    text-align: center;
    border-right: 1px solid #fff;
    cursor: pointer;
  }

  .products li:last-child {
    border: none;
  }

  .search {
    background: rgba(11, 52, 20, 0.8);
    height: 100vh;
    position: fixed;
    width: 100%;
    top: 0;
    left: 0;
    z-index: 99;
  }

  .search-head {
    background: rgba(11, 52, 20, 1);
    height: 97px;
  }

  .search-form {
    height: 50px;
    width: 500px;
    margin-right: 120px;
    margin-top: 20px;
    float: right;
    transform:scale(0);
    transform-origin: 100% 100%;

  }

  .form-enlarge {
    animation: enlarge 0.5s;
    -webkit-animation: enlarge 0.5s; /* Safari 与 Chrome */
    -webkit-animation-fill-mode: forwards;
    animation-fill-mode: forwards;
  }

  .form-narrow {
    animation: narrow 0.5s;
    -webkit-animation: narrow 0.5s; /* Safari 与 Chrome */
    -webkit-animation-fill-mode: forwards;
    animation-fill-mode: forwards;
  }

  .form-left {
    background: #fff;
    border-radius: 5px;
  }

  .form-left button {
    height: 50px;
    width: 50px;
    background: none;
    border: none;
    float: right;
    font-size: 24px;
    cursor: pointer;
  }

  .form-left {
    width: calc(100% - 100px);
    float: left;
  }

  .form-left input {
    width: calc(100% - 70px);
    padding: 0 10px;
    line-height: 50px;
    border: none;
    background: none;
    float: left;
  }

  .form-left input:focus {
    outline: none;
  }

  .close {
    float: right;
    font-size: 24px;
    color: #fff;
    margin-top: 20px;
    cursor: pointer;
  }

  @keyframes enlarge
  {
    from {
      transform:scale(0);
    }
    to {
      transform:scale(1);
    }
  }

  @-webkit-keyframes enlarge
  {
    from {
      transform:scale(0);
    }
    to {
      transform:scale(1);
    }
  }

  @keyframes narrow
  {
    from {
      transform:scale(1);
    }
    to {
      transform:scale(0);
    }
  }

  @-webkit-keyframes narrow
  {
    from {
      transform:scale(1);
    }
    to {
      transform:scale(0);
    }
  }
</style>
